package com.example.musicplayer.settings;

import android.graphics.Bitmap;

import com.example.musicplayer.DataLoadManager;
import com.example.musicplayer.commonUtils.DrawUtil;
import com.example.musicplayer.musicTools.Lyric;
import com.example.musicplayer.user.User;

public class MusicPlayerSettings {
    //when load music menu cover, the num of thread to enable
    private static final int THREAD_LOAD_MENU_COVER = 10;
    //the tab in main activity, that distance from the left or right edge
    private static int sGapToEdge = 100;
    //the least time to increase the listen counts of music
    private static int sTimeToIncreaseListenCounts = 30 * 1000;
    //the limit of user nick name
    private static int sLengthOfUserName = 20;
    //in music list activity, the back to top button appear
    private static int sBackToTopButtonAppear = 10;
    //the length limit of music menu name
    private static int sLengthOfMenuName = 20;
    //in menu details activity, the least music counts to show location
    private static int sLeastMusicCountsUseLocation = 20;
    //the alpha of main color in music play screen
    private static int sAlphaOfPictureMainColor = 222;
    //the lyric is simplified or traditional
    private static int sLyricChinese = Lyric.SIMPLIFIED;
    /**
     * if auto into music play screen when click music item in music list
     */
    private static boolean sAutoIntoPlayScreen = false;
    /**
     * if still play music when other app play video or audio
     */
    private static boolean sAllowPlayWithOther = false;
    /**
     * if display notification bar when play music
     */
    private static boolean sUseNotificationBar = true;
    /**
     * if enable desktop lyric
     */
    private static boolean sDesktopLyric = false;
    /**
     * if lock the desktop lyric
     */
    private static boolean sDesktopLyricLock = false;
    /**
     * if show desktop lyric in app
     */
    private static boolean sDesktopLyricInApp = false;
    /**
     * if there is animation effect when switch screen
     */
    private static boolean sAnimEffect = true;
    /**
     * if set play screen background
     */
    private static boolean sSetPlayScreenBg = false;
    /**
     * if set music play list background
     */
    private static boolean sSetMusicPlayListBg = false;
    /**
     * if display visualizer in play screen
     */
    private static boolean sDisplayVisualizer = false;
    /**
     * if enable sound effect bass boost
     */
    private static boolean sEnableBassBoost = false;
    /**
     * the strength of bass boost
     */
    private static int sBassBoostStrength;
    /**
     * if enable virtual sound effect
     */
    private static boolean sEnableVirtual = false;
    /**
     * the strength of virtual
     */
    private static int sVirtualStrength;
    private static boolean sEnableReverb = false;
    private static int sReverbLevel;
    /**
     * if add music to the tail of play list
     */
    private static boolean sAddToPlayListTail = false;

    public static void exitLoginState() {
        sAnimEffect = true;
    }

    public static int getThreadLoadMenuCover() {
        return THREAD_LOAD_MENU_COVER;
    }

    public static void setGapToEdge(int gapToEdge) {
        sGapToEdge = gapToEdge;
    }

    public static int getGapToEdge() {
        return sGapToEdge;
    }

    public static void setTimeToIncreaseListenCounts(int timeToIncreaseListenCounts) {
        if (timeToIncreaseListenCounts > 0)
            sTimeToIncreaseListenCounts = timeToIncreaseListenCounts;
    }

    public static int getTimeToIncreaseListenCounts() {
        return sTimeToIncreaseListenCounts;
    }

    public static void setLengthOfUserName(int lengthOfUserName) {
        if (lengthOfUserName > 0) {
            sLengthOfUserName = lengthOfUserName;
        }
    }

    public static int getLengthOfUserName() {
        return sLengthOfUserName;
    }

    public static void setBackToTopButtonAppear(int backToTopButtonAppear) {
        if (backToTopButtonAppear >= 0)
            sBackToTopButtonAppear = backToTopButtonAppear;
    }

    public static int getBackToTopButtonAppear() {
        return sBackToTopButtonAppear;
    }

    public static void setLengthOfMenuName(int lengthOfMenuName) {
        if (lengthOfMenuName > 0)
            sLengthOfMenuName = lengthOfMenuName;
    }

    public static int getLengthOfMenuName() {
        return sLengthOfMenuName;
    }

    public static void setLeastMusicCountsUseLocation(int leastMusicCountsUseLocation) {
        if (leastMusicCountsUseLocation >= 1)
            sLeastMusicCountsUseLocation = leastMusicCountsUseLocation;
    }

    public static int getLeastMusicCountsUseLocation() {
        return sLeastMusicCountsUseLocation;
    }

    public static void setAlphaOfPictureMainColor(int alpha) {
        if (alpha >= 0 && alpha <= 255)
            sAlphaOfPictureMainColor = alpha;
    }

    public static int getAlphaOfPictureMainColor() {
        return sAlphaOfPictureMainColor;
    }

    public static void setLyricChinese(int lyricChinese) {
        if (lyricChinese == Lyric.SIMPLIFIED || lyricChinese == Lyric.TRADITIONAL) {
            sLyricChinese = lyricChinese;
        }
    }

    public static int getLyricChinese() {
        return sLyricChinese;
    }

    public static void initAutoIntoPlayScreen(boolean autoIntoPlayScreen) {
        sAutoIntoPlayScreen = autoIntoPlayScreen;
    }

    public static void setAutoIntoPlayScreen(boolean autoIntoPlayScreen) {
        if (DataLoadManager.getInstance() != null) {
            sAutoIntoPlayScreen = autoIntoPlayScreen;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.AUTO_INTO_PLAY_SCREEN
                    , autoIntoPlayScreen);
        }
    }

    public static boolean isAutoIntoPlayScreen() {
        return sAutoIntoPlayScreen;
    }

    public static void initAllowPlayWithOther(boolean allowPlay) {
        sAllowPlayWithOther = allowPlay;
    }

    public static void setAllowPlayWithOther(boolean allow) {
        if (DataLoadManager.getInstance() != null) {
            sAllowPlayWithOther = allow;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.ALLOW_PLAY_WITH_OTHER, allow);
        }
    }

    public static boolean allowPlayWithOther() {
        return sAllowPlayWithOther;
    }

    public static void initUseNotificationBar(boolean enable) {
        sUseNotificationBar = enable;
    }

    public static void setUseNotificationBar(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sUseNotificationBar = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.USE_NOTIFICATION_BAR, enable);
        }
    }

    public static boolean isUseNotificationBar() {
        return sUseNotificationBar;
    }

    public static void initDesktopLyricInApp(boolean enable) {
        sDesktopLyricInApp = enable;
    }

    public static void setDesktopLyricInApp(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sDesktopLyricInApp = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.DESKTOP_LYRIC_IN_APP, enable);
        }
    }

    public static boolean isDesktopLyricInApp() {
        return sDesktopLyricInApp;
    }

    public static void initDesktopLyric(boolean enable) {
        sDesktopLyric = enable;
    }

    public static void setDesktopLyric(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sDesktopLyric = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.DESKTOP_LYRIC, enable);
        }
    }

    public static boolean isDesktopLyric() {
        return sDesktopLyric;
    }

    public static void initDesktopLyricLock(boolean locked) {
        sDesktopLyricLock = locked;
    }

    public static void setDesktopLyricLock(boolean locked) {
        if (DataLoadManager.getInstance() != null) {
            sDesktopLyricLock = locked;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.DESKTOP_LYRIC_LOCK, locked);
        }
    }

    public static boolean isDesktopLyricLock() {
        return sDesktopLyricLock;
    }

    public static void initAnimEffect(boolean enable) {
        sAnimEffect = enable;
    }

    public static void setAnimEffect(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sAnimEffect = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.ANIM_EFFECT, enable);
        }
    }

    public static boolean isAnimEffect() {
        return sAnimEffect;
    }

    public static void initSetPlayScreenBg(boolean enable) {
        sSetPlayScreenBg = enable;
    }

    public static void setSetPlayScreenBg(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sSetPlayScreenBg = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.PLAY_SCREEN_BACKGROUND, enable);
        }
    }

    public static boolean isSetPlayScreenBg() {
        return sSetPlayScreenBg;
    }

    public static void initSetMusicPlayListBg(boolean enable) {
        sSetMusicPlayListBg = enable;
    }

    public static void setSetMusicPlayListBg(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sSetMusicPlayListBg = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.MUSIC_PLAY_LIST_BACKGROUND, enable);
        }
    }

    public static boolean isSetMusicPlayListBg() {
        return sSetMusicPlayListBg;
    }

    public static void initDisplayVisualizer(boolean enable) {
        sDisplayVisualizer = enable;
    }

    public static void setDisplayVisualizer(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sDisplayVisualizer = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.DISPLAY_VISUALIZER, enable);
        }
    }

    public static boolean isDisplayVisualizer() {
        return sDisplayVisualizer;
    }

    public static void initEnableBassBoost(boolean enable) {
        sEnableBassBoost = enable;
    }

    public static void setEnableBassBoost(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sEnableBassBoost = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.ENABLE_BASS_BOOST, enable);
        }
    }

    public static boolean isEnableBassBoost() {
        return sEnableBassBoost;
    }

    public static void initBassBoostStrength(int strength) {
        sBassBoostStrength = strength;
    }

    public static void setBassBoostStrength(int strength) {
        if (DataLoadManager.getInstance() != null) {
            sBassBoostStrength = strength;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.BASS_BOOST_STRENGTH, strength);
        }
    }

    public static int getBassBoostStrength() {
        return sBassBoostStrength;
    }

    public static void initEnableVirtual(boolean enable) {
        sEnableVirtual = enable;
    }

    public static void setEnableVirtual(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sEnableVirtual = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.ENABLE_VIRTUAL, enable);
        }
    }

    public static boolean isEnableVirtual() {
        return sEnableVirtual;
    }

    public static void initVirtualStrength(int strength) {
        sVirtualStrength = strength;
    }

    public static void setVirtualStrength(int strength) {
        if (DataLoadManager.getInstance() != null) {
            sVirtualStrength = strength;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.VIRTUAL_STRENGTH, strength);
        }
    }

    public static int getVirtualStrength() {
        return sVirtualStrength;
    }

    public static void initEnableReverb(boolean enable) {
        sEnableReverb = enable;
    }

    public static void setEnableReverb(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sEnableReverb = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.ENABLE_REVERB, enable);
        }
    }

    public static boolean isEnableReverb() {
        return sEnableReverb;
    }

    public static void initReverbLevel(int level) {
        sReverbLevel = level;
    }

    public static void setReverbLevel(int level) {
        if (DataLoadManager.getInstance() != null) {
            sReverbLevel = level;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.REVERB_LEVEL, level);
        }
    }

    public static int getReverbLevel() {
        return sReverbLevel;
    }

    public static void setPlayScreenImage(int id) {
        if (DataLoadManager.getInstance() != null) {
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.PLAY_SCREEN_IMAGE, id);
        }
    }

    public static int getPlayScreenImageId() {
        if (DataLoadManager.getInstance() != null) {
            return DataLoadManager.getInstance().readOneBaseData(DataLoadManager.PLAY_SCREEN_IMAGE, 0);
        }
        return 0;
    }

    public static Bitmap getPlayScreenImageBitmap() {
        if (DataLoadManager.getInstance() != null) {
            int id = DataLoadManager.getInstance().readOneBaseData(DataLoadManager.PLAY_SCREEN_IMAGE, 0);
            return User.getUserPhoto(id);
        }
        return DrawUtil.getDefaultMusicMenuBitmap();
    }

    public static void setMusicPlayListImage(int id) {
        if (DataLoadManager.getInstance() != null) {
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.MUSIC_PLAY_LIST_IMAGE, id);
        }
    }

    public static int getMusicPlayListImageId() {
        if (DataLoadManager.getInstance() != null) {
            return DataLoadManager.getInstance().readOneBaseData(DataLoadManager.MUSIC_PLAY_LIST_IMAGE, 0);
        }
        return 0;
    }

    public static Bitmap getMusicPlayListImageBitmap() {
        if (DataLoadManager.getInstance() != null) {
            int id = DataLoadManager.getInstance().readOneBaseData(DataLoadManager.MUSIC_PLAY_LIST_IMAGE, 0);
            return User.getUserPhoto(id);
        }
        return DrawUtil.getDefaultMusicMenuBitmap();
    }

    public static void initAddToPlayListTail(boolean enable) {
        sAddToPlayListTail = enable;
    }

    public static void setAddToPlayListTail(boolean enable) {
        if (DataLoadManager.getInstance() != null) {
            sAddToPlayListTail = enable;
            DataLoadManager.getInstance().writeOneBaseData(DataLoadManager.ADD_TO_PLAY_LIST_TAIL, enable);
        }
    }

    public static boolean isAddToPlayListTail() {
        return sAddToPlayListTail;
    }
}